#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc,char **argv)
{
	int fd;
	int val = 1;
	char *filename;
	
	if(argc != 3)
	{
		printf("Usage:\n");
		printf("%s <dev> <on|off>\n",argv[0]);
		printf("%s /dev/leds  on\n",argv[0]);
		printf("%s /dev/leds  off\n",argv[0]);
		printf("%s /dev/led1  on\n",argv[0]);
		printf("%s /dev/led1  off\n",argv[0]);
		return 0;
	}
	
	filename = argv[1];
	
	fd = open(filename,O_RDWR);
	if(fd<0)
		printf("can't open!\n");
	
	
	if(strcmp(argv[2],"on")==0)
	{
		val = 1;
		write(fd,&val,1);
	}else if(strcmp(argv[2],"off")==0){
		val = 0;
		write(fd,&val,1);
	}else{
		printf("Usage:\n");
		printf("%s <dev> <on|off>\n",argv[0]);
		printf("%s /dev/leds  on\n",argv[0]);
		printf("%s /dev/leds  off\n",argv[0]);
		printf("%s /dev/led1  on\n",argv[0]);
		printf("%s /dev/led1  off\n",argv[0]);
	}
	
	return 0;
}
